home *** CD-ROM | disk | FTP | other *** search
-
- /* Test file to see how the compiler handles volatile and const
- * keywords.
- *
- * Compile normally, then inspect the assembly output
- * (using DumpObj or whatever) to see if
- * REGISTER_ADDRESS is written to. MPW 3.2 will not comply with
- * this intended use. Then, change the last line to
- * *TheStrobe=1;
- * and notice the difference in the assembly code.
- */
-
- #define REGISTER_ADDRESS 0x3000000
-
- main() {
-
- /* RegStrobe is a type of register that is 8 bits wide. It is
- * a constant pointer to a volatile entity.
- */
- typedef unsigned char volatile * const RegStrobe;
-
- /* Obviously, you won't want to EXECUTE this program on your
- * Mac since it will write to a hard-coded address, which
- * will only be polite in your target environment
- */
- RegStrobe TheStrobe = (RegStrobe) REGISTER_ADDRESS;
-
- /* whack the register
- */
- *TheStrobe; /* Any compiler that optimizes this out is not
- * respecting your use of const and volatile
- * keywords. While not strictly a violation
- * of the ANSI C standard, it is sub-optimal
- * for purposes of embedded development. Use
- * caution!
- */
- }
-
-